﻿using Microsoft.Extensions.Configuration;

namespace Maltose.Data
{
    /// <summary>
    /// 获取数据库配置连接
    /// </summary>
    internal class DataServiceConfig
    {
        static IConfigurationRoot _Configuration;
        static readonly object _JsonSingLock = new object();

        /// <summary>
        /// 获取值
        /// </summary>
        public static IConfigurationRoot Configuration
        {
            get
            {
                if (_Configuration == null)
                {
                    lock (_JsonSingLock)
                    {
                        if (_Configuration == null)
                        {
                            var builder = new ConfigurationBuilder();
                            builder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                            _Configuration = builder.Build();
                            return _Configuration;
                        }
                    }
                }
                return _Configuration;
            }
        }
    }
}
